#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>


using namespace std;
//queue derection a > b, means back > front
priority_queue<int, vector<int>, greater<int>> a;

int main()
{
    int n;
    scanf("%d", &n);
    for(int i=0; i < n; i++)
    {
        int x;
        scanf("%d", &x);
        a.push(x);
    }
    long long res = 0;
    while(!a.empty())
    {
        int x = a.top(), y = 0;
        a.pop();
        if (a.empty())
        {
            res += x;
            break;
        }
        y = a.top();
        a.pop();
        res += (x+y);
        if(a.empty())break;
        a.push(x+y);
    }
    printf("%lld\n", res);
    return 0;
}